package com.xzm.MQ.utils;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class RabbitMQUtils{
    private static ConnectionFactory connectionFactory;
    static{
        connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("47.102.155.48");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("test");
        connectionFactory.setPassword("password");
        connectionFactory.setVirtualHost("/test");
    }
    public static Connection getConnection(){
        try {
            return connectionFactory.newConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static void closeChannelAndConnetion(Channel channel,Connection connection){
            try {
                if(channel!=null) channel.close();
                if(connection!=null) connection.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
    }
}
